/**************************************************************************
 *         Copyright(c) 2007 by Sunplus mMedia  Technology Co., Ltd.       *
 *                                                                         *
 *  This software is copyrighted by and is the property of Sunplus mMedia  *
 *  Technology Co., Ltd. All rights are reserved by Sunplus mMedia Techno- *
 *  logy Co., Ltd. This software may only be used in accordance with the   *
 *  corresponding license agreement. Any unauthorized use, duplication,    *
 *  distribution, or disclosure of this software is expressly forbidden.   *
 *                                                                         *
 *  This Copyright notice "M U S T" not be removed or modified without     *
 *  prior written consent of Sunplus mMedia Technology  Co., Ltd.          *
 *                                                                         *
 *  Sunplus mMedia Technology Co., Ltd. reserves the right to modify this  *
 *  software without notice.                                               *
 *                                                                         *
 *  Sunplus mMedia Technology Co., Ltd.                                    *
 *  19-1, Innovation First Road, Science-Based Industrial Park,            *
 *  Hsin-Chu, Taiwan, R.O.C.                                               *
 *                                                                         *
 **************************************************************************/
#include "general.h"
#include "os_msg.h"
#include "main.h"
#include "key_scan.h"
#include "dos32.h"

#include "sp1k_aud_api.h"
#include "sp1k_vfs_api.h"
#include "sp1k_hal_api.h"
#include "sp1k_pb_api.h"
#include "sp1k_osd_api.h"
#include "sp1k_disp_api.h"
#include "sp1k_rsvblk_api.h"

#include "app_main.h"
#include "app_menu_event.h"
#include "app_menu_micro.h"
#include "app_menu_core.h"
#include "app_menu_tab.h"
#include "app_menu.h"
#include "app_still_play.h"
#include "app_multi_play.h"
#include "app_ui_osd.h"
#include "app_ui_power.h"
#include "app_ui_para.h"
#include "app_osd_icon.h"
#include "app_still_view.h"

/**************************************************************************
 *                           C O N S T A N T S                            *
 **************************************************************************/

/**************************************************************************
 *                              M A C R O S                               *
 **************************************************************************/

/**************************************************************************
 *                          D A T A    T Y P E S                          *
 **************************************************************************/

/**************************************************************************
 *                         G L O B A L    D A T A                         *
 **************************************************************************/

/**************************************************************************
 *                 E X T E R N A L    R E F E R E N C E S                 *
 **************************************************************************/
extern SIMAGE xdata pbFile;
//extern xdata UINT8 OsdMaxX;
//extern xdata UINT8 OsdMaxY;

//-----------------------------------------------------------------------------
//appMenuEvent_VerShow
//-----------------------------------------------------------------------------

/**
 * @brief		appMenuEvent_VerShow
 * @param	NULL
 * @retval	NULL
 * @see
 * @author	Phil Lin
 * @since		2008-11-11
 * @todo		Something need to be done.
 * @bug		a bug need to be resolved.
*/
UINT8 appMenuEvent_VerShow(void)
{
	UINT8 strVer[16] = "VER.";
	UINT8 strDate[16] = {0};
	UINT8 strTime[16] = {0};
	UINT8 OsdMaxX, OsdMaxY;

	sp1kOsdLayoutAttrGet(&OsdMaxX, &OsdMaxY);
	
	strcpy(strVer + 4, sp1kFWVerGet());
	strcpy(strDate, sp1kFWDateGet());
	strcpy(strTime, sp1kFWTimeGet());
	
	sp1kOsdClear(ID_ICON_NONE, OSD_ATTR_COLOR_BLACK | OSD_ATTR_MODE_NOMAL | OSD_ATTR_BACK_EN);
	sp1kOsdSelWinSet(-1, -1, -1, -1, 0, -1);
	
	sp1kOsdStrDraw((OsdMaxX - strlen(strVer)) >> 1, OsdMaxY >> 1, strVer, OSD_ATTR_COLOR_CYAN | OSD_ATTR_MODE_NOMAL | OSD_ATTR_BACK_EN);
	sp1kOsdStrDraw((OsdMaxX - strlen(strDate)), (OsdMaxY) - 2, strDate, OSD_ATTR_COLOR_RED| OSD_ATTR_MODE_NOMAL | OSD_ATTR_BACK_EN);
	sp1kOsdStrDraw((OsdMaxX - strlen(strTime)), (OsdMaxY) - 1 , strTime, OSD_ATTR_COLOR_RED | OSD_ATTR_MODE_NOMAL | OSD_ATTR_BACK_EN);

	return SUCCESS;
}


//-----------------------------------------------------------------------------
//appMenuEvent_VoiceMemoAdd
//-----------------------------------------------------------------------------

/**
 * @brief		appMenuEvent_VoiceMemoAdd
 * @param	NULL
 * @retval	NULL
 * @see
 * @author	Phil Lin
 * @since		2008-02-20
 * @todo		Something need to be done.
 * @bug		a bug need to be resolved.
*/

UINT8 appMenuEvent_VoiceMemoAdd(void)
{
	UINT32 time;
	UINT8 fName[12];	
	UINT16 fHdl;
	
	//xian ++ 20090423, #34966
	if(1 == appSDProtectStatusGet())
	{
		uiOsdDialogDisp(ID_STR_CARD_LOCKED_, 1000);
		menuExit(); 
		return FAIL;
	}
	//xian --
    
	if (pbFile.bImageProtect != TRUE) { 
		sp1kAudioRecFreqSet(RecordFrequence44khz);  	//xian ++ 20090423, #32339
		uiUpdateAudRecRemainTime(&time);

		//30s max in fact, another 30s for reserved
		if (time >= 30) {
			//check if there is any voice memo belong the current image file
			strcpy(fName, pbFile.FileName);
			fName[8] = 'W';
			fName[9] = 'A';
			fName[10] = 'V';		
			fHdl = File_Open(fName, K_DOS_ReadFile, 0);
			if (fHdl) {
				//delete old vioce memo file
				//CPrintf("delete old file");
				sp1kVfsDel(fName);
				File_Close(fHdl, fName, K_DOS_ReadFile, 0); 			
			}
            pbDZoomPause(); //xian ++ 20080624, fix bug #26147           
			sp1kAudioRecTypeSet(AUDIO_TYPE_VOICE);
			osMsgPost(SP1K_MSG_STATE_TO_AUDIO_REC);
			return SUCCESS;
		} else {
			uiUpdateOSDMemFull();
			menuProcParent ();
			menuProcDisp(); 			
		}
	}else {
		menuExit();
		uiOsdDialogDisp(ID_STR_FILE_LOCKED_, 1000); 	
	}

	return FAIL;
}

//-----------------------------------------------------------------------------
//appMenuEvent_VoiceMemoDel
//-----------------------------------------------------------------------------

/**
 * @brief		appMenuEvent_VoiceMemoDel
 * @param	NULL
 * @retval	NULL
 * @see
 * @author	Phil Lin
 * @since		2008-02-20
 * @todo		Something need to be done.
 * @bug		a bug need to be resolved.
*/

UINT8 appMenuEvent_VoiceMemoDel(void)
{
	UINT8 fName[12];
	
	//xian ++ 20090423, #34966
	if(1 == appSDProtectStatusGet())
	{
		uiOsdDialogDisp(ID_STR_CARD_LOCKED_, 1000);
		menuExit(); 
		return FAIL;
	}
	//xian --

	if (pbFile.bImageProtect != TRUE) {
		strcpy(fName, pbFile.FileName);
		fName[8] = 'W';
		fName[9] = 'A';
		fName[10] = 'V';
		//printf("Del file name %s\n", fName);
		menuExit();
		if (sp1kVfsDel(fName) == TRUE) {
			return SUCCESS;
			//printf("voice del err!\n");
		}
	} else {
		menuExit();
		uiOsdDialogDisp(ID_STR_FILE_LOCKED_, 1000);
	}
	
	return FAIL;
}
//-----------------------------------------------------------------------------
//appMenuEvent_DeleteSingle
//-----------------------------------------------------------------------------

/**
 * @brief		appMenuEvent_DeleteSingle
 * @param	NULL
 * @retval	NULL
 * @see
 * @author	Phil Lin
 * @since		2008-02-20
 * @todo		Something need to be done.
 * @bug		a bug need to be resolved.
*/

UINT8 appMenuEvent_DeleteSingle(void)
{		
	UINT8 Xoffset = 0;
	
	if(1 == appSDProtectStatusGet())
	{
		uiOsdDialogDisp(ID_STR_CARD_LOCKED_, 1000);
		menuExit(); 
		return FAIL;
	}

	if(pbFile.bImageProtect == TRUE)
	{
		uiOsdDialogDisp(ID_STR_FILE_LOCKED_, 1000);
		menuExit(); 
		return FAIL;
	}
	
	if(appFileDelete(SP1K_FILE_PROC_ONE)) {
		if (appPreStateGet(0) == APP_STATE_MUTI_PLAY) {
			menuExit();
			appMultiPlayInit(SP1K_PB_INIT_FULL);
			return SUCCESS;
		}
		//if there is any image
		if(appPanelTypeGet() == 0) {
			Xoffset = 1;
		}		
		menuProcDisp();
		uiUpdateOSDPbFileNum();
		uiUpdateOSDPbType(0 + Xoffset, 0 , 5);
	} else {
		menuExit(); 
	}
	
	return SUCCESS;
}
//-----------------------------------------------------------------------------
//appMenuEvent_DeleteAll
//-----------------------------------------------------------------------------

/**
 * @brief		appMenuEvent_DeleteAll
 * @param	NULL
 * @retval	NULL
 * @see
 * @author	Phil Lin
 * @since		2008-02-20
 * @todo		Something need to be done.
 * @bug		a bug need to be resolved.
*/
//jintao.liu Note:
//use LastMode = appPreStateGet(0); to get last mode
#if 0//old method
UINT8 appMenuEvent_DeleteAll(void)
{
	if(1 == appSDProtectStatusGet())//jintao.liu 2008-5-6 sd lock
	{
		uiOsdDialogDisp(ID_STR_CARD_LOCKED_, 1000);
		menuExit(); 
		return FAIL;
	}
	
	appUiBusyWait(250, 1);	
	appFileDelete(SP1K_FILE_PROC_ALL);
	pbFile.dwIndex = sp1kPbFileCntGet();
	appUiBusyExit();

	if(pbFile.bImageProtect == TRUE)			
	{
		appStillPlayNext(0xFF); //2008-5-22 for mantis 25200
		uiOsdDialogDisp(ID_STR_FILE_LOCKED_, 1000);
	}
	else
	{
		sp1kDispImgWinEn(0);
	}
	menuExit(); 
	uiRemainPixInit();
	return SUCCESS;
}
#else//new method for pb_9 errors
UINT8 appMenuEvent_DeleteAll(void)
{
	UINT8 LastMode;
	
	if(1 == appSDProtectStatusGet())//jintao.liu 2008-5-6 sd lock
	{
		uiOsdDialogDisp(ID_STR_CARD_LOCKED_, 1000);
		menuExit(); 
		return FAIL;
	}
	
	appUiBusyWait(250, 1);	
	appFileDelete(SP1K_FILE_PROC_ALL);
	
	pbFile.dwIndex = sp1kPbFileCntGet();
	if (0 != pbFile.dwIndex)
	{
		appPbFileInfoUpdate();//to refresh "pbFile".
	}
	
	appUiBusyExit();

	LastMode = appPreStateGet(0);

	if (APP_STATE_MUTI_PLAY != LastMode)
	{
		if((pbFile.dwIndex != 0)) //&& (pbFile.bImageProtect == TRUE))			
		{
			appStillPlayNext(0xFF); //2008-5-22 for mantis 25200
			uiOsdDialogDisp(ID_STR_FILE_LOCKED_, 1000);
		}
		else
		{
			sp1kDispImgWinEn(0);
		}
	}
	else
	{
		if((0 != pbFile.dwIndex) && (pbFile.bImageProtect == TRUE))			
		{
			uiOsdDialogDisp(ID_STR_FILE_LOCKED_, 1000);
		}
		appMultiPlayInit(SP1K_PB_INIT_FULL);
	}
	
	menuExit(); 
	uiRemainPixInit();
	return SUCCESS;
}
#endif

//-----------------------------------------------------------------------------
//appMenuEvent_SlideShowStart
//-----------------------------------------------------------------------------

/**
 * @brief		appMenuEvent_SlideShowStart
 * @param	NULL
 * @retval	NULL
 * @see
 * @author	Phil Lin
 * @since		2008-02-20
 * @todo		Something need to be done.
 * @bug 	a bug need to be resolved.
*/

UINT8 appMenuEvent_SlideShowStart(void)
{
	menuExit(); 
	//Do not switch to still playback mode, to slide show directly
	osMsgFlush();
	osMsgPost(SP1K_MSG_STATE_TO_SLIDE_SHOW);

	return SUCCESS;
}

//-----------------------------------------------------------------------------
//appMenuEvent_StartUpImgSet
//-----------------------------------------------------------------------------

/**
 * @brief		appMenuEvent_StartUpImgSet
 * @param	NULL
 * @retval	NULL
 * @see
 * @author	Phil Lin
 * @since		2008-02-20
 * @todo		Something need to be done.
 * @bug 	a bug need to be resolved.
*/

UINT8 appMenuEvent_StartUpImgSet(void)
{
	UINT32 addr;
	uiPara_t* puiPara = appUiParaGet();
	UINT8 status;
		
	sp1kPbUserStartImgGet(&addr);	
	ENTER_CRITICAL(status);
	sp1kNandRsvWrite(0x81, addr << 1);
	EXIT_CRITICAL(status);
	puiPara->OpenPic = PB_OPENPIC_USER_DEF;
	menuExit();

	return SUCCESS;
}

//-----------------------------------------------------------------------------
//appMenuEvent_ImgRotate
//-----------------------------------------------------------------------------

/**
 * @brief		appMenuEvent_ImgRotate
 * @param	NULL
 * @retval	NULL
 * @see
 * @author	Phil Lin
 * @since		2008-11-11
 * @todo		Something need to be done.
 * @bug 	a bug need to be resolved.
*/

UINT8 appMenuEvent_ImgRotate(UINT32 menuPos)
{
	PBFile_t fileInfo;

	if (MENU_MARK_ROTATE_ROTATE == menuPos)
	{
		sp1kPbFileInfoGet(DOS_FileIndexGet(pbFile.dwIndex), &fileInfo);
		sp1kPbParamSet(PB_PARAM_ROT, 1);		
		sp1kPbSingleImgPlay(DOS_FileIndexGet(pbFile.dwIndex));
	}
	else if (MENU_MARK_ROTATE_SAVE == menuPos)
	{
		UINT32 diskFreeSpace;	

		if(1 == appSDProtectStatusGet()) //card lock remainder
		{
			uiOsdDialogDisp(ID_STR_CARD_LOCKED_, 1000);
			menuProcDisp();
			return FAIL;
		}
		
	#ifdef DOS32_SUPPORT
		diskFreeSpace = (UINT32)1024 * (UINT32)DOS_GetDiskSpace();
	#else
		diskFreeSpace = (UINT32)G_DOS_ClusterSize * (UINT32)DOS_GetDiskSpace();
	#endif

		if (diskFreeSpace < 1000000)
		{
			sp1kOsdSelWinSet(-1, -1, -1, -1, 0, -1);
			uiUpdateOSDMemFull();
			menuProcDisp();
		}
		else{
			appUiBusyWait(250, 0);
			
			sp1kPbFileInfoGet(DOS_FileIndexGet(pbFile.dwIndex), &fileInfo);
			sp1kPbImgRotate(&fileInfo);
			sp1kPbParamSet(PB_PARAM_ROT, 0);	//clear  
			
			pbFile.dwIndex = sp1kPbFileCntGet();			
			sp1kPbSingleImgPlay(DOS_FileIndexGet(pbFile.dwIndex));
			//osMsgPost(SP1K_MSG_STATE_TO_STILL_PLAY);

			appUiBusyExit();
			menuExit();
		}
	}
	else
	{
		sp1kPbParamSet(PB_PARAM_ROT, 0);	//clear  
		sp1kPbSingleImgPlay(DOS_FileIndexGet(pbFile.dwIndex));
		menuProcParent();
		menuProcDisp();
	}
	
	return SUCCESS;
}

//-----------------------------------------------------------------------------
//appMenuEvent_ImgEffect
//-----------------------------------------------------------------------------

/**
 * @brief		appMenuEvent_ImgEffect
 * @param	NULL
 * @retval	NULL
 * @see
 * @author	Phil Lin
 * @since		2008-11-11
 * @todo		Something need to be done.
 * @bug 	a bug need to be resolved.
*/

UINT8 appMenuEvent_ImgEffect(UINT32 menuPos)
{
	PBEffectList_t imgEffect;
	PBFile_t fileInfo;
	
	if((menuPos >= MENU_MARK_PB_EFFECT_FIRST) && (menuPos < MENU_MARK_PB_EFFECT_OVER)){
		switch (menuPos) {				
			case MENU_MARK_PB_EFFECT_BW:
				imgEffect = PB_IMG_EFFECT_BLACKWHITE;
				break;
			case MENU_MARK_PB_EFFECT_SEPIA:
				imgEffect = PB_IMG_EFFECT_SEPIA;
				break;
			case MENU_MARK_PB_EFFECT_NEGATIVE:
				imgEffect = PB_IMG_EFFECT_NEGTIVE;
				break;
			case MENU_MARK_PB_EFFECT_RED:
				imgEffect = PB_IMG_EFFECT_RED;
				break;
			case MENU_MARK_PB_EFFECT_GREEN:
				imgEffect = PB_IMG_EFFECT_GREEN;
				break;
			case MENU_MARK_PB_EFFECT_BLUE:
				imgEffect = PB_IMG_EFFECT_BLUE;
				break;
			case MENU_MARK_PB_EFFECT_BINARIZE:
				imgEffect = PB_IMG_EFFECT_BINARIZE;
				break;
			case MENU_MARK_PB_EFFECT_SUNSET:
				imgEffect = PB_IMG_EFFECT_SUNSET;
				break;
			case MENU_MARK_PB_EFFECT_WARM:
				imgEffect = PB_IMG_EFFECT_WARM;
				break;
			case MENU_MARK_PB_EFFECT_COLD:
				imgEffect = PB_IMG_EFFECT_COLD;
				break;
			case MENU_MARK_PB_EFFECT_CONTRAST:
				imgEffect = PB_IMG_EFFECT_CONTRAST;
				break;
			default:
				imgEffect = PB_IMG_EFFECT_NORMAL;
				break;
		}
	}
/* ------ Note: Demo code zone start flag, don't modify or delete this line!!! ------ */
	else {
		imgEffect=PB_IMG_EFFECT_MAX;
	
		switch (menuPos) {				
			case MENU_MARK_PB_DISTORTION_H_PINCH:
				imgEffect += SPE_DISTORT_H_PINCH;
				break;
			case MENU_MARK_PB_DISTORTION_H_PUNCH:
				imgEffect += SPE_DISTORT_H_PUNCH;
				break;
			case MENU_MARK_PB_DISTORTION_V_PINCH:
				imgEffect += SPE_DISTORT_V_PINCH;
				break;
			case MENU_MARK_PB_DISTORTION_V_PUNCH:
				imgEffect += SPE_DISTORT_V_PUNCH;
				break;
			case MENU_MARK_PB_DISTORTION_H_SHRINK:
				imgEffect += SPE_DISTORT_H_SHRINK;
				break;
			case MENU_MARK_PB_DISTORTION_V_SHRINK:
				imgEffect += SPE_DISTORT_V_SHRINK;
				break;
			case MENU_MARK_PB_DISTORTION_H_STRETCH:
				imgEffect += SPE_DISTORT_H_STRETCH;
				break;
			case MENU_MARK_PB_DISTORTION_V_STRETCH:
				imgEffect += SPE_DISTORT_V_STRETCH;
				break;
			case MENU_MARK_PB_DISTORTION_WAVY:
				imgEffect += SPE_DISTORT_WAVY;
				break;
			case MENU_MARK_PB_DISTORTION_HOURGLASS:
				imgEffect += SPE_DISTORT_H_HOURGLASS;
				break;
			case MENU_MARK_PB_DISTORTION_BUBBLE:
				imgEffect += SPE_DISTORT_BUBBLE;
				break;
			case MENU_MARK_PB_DISTORTION_BUBBLE_FILL:
				imgEffect += SPE_DISTORT_BUBBLE_FILL;
				break;
			default:
				imgEffect = PB_IMG_EFFECT_NORMAL;
				break;
			}
	}
/* ------ Note: Demo code zone end flag, don't modify or delete this line!!! ------ */		
	
	if(1 == appSDProtectStatusGet()) //card lock remainder
	{
		uiOsdDialogDisp(ID_STR_CARD_LOCKED_, 1000);
		menuProcDisp();
		return FAIL;
	}
	
	if (imgEffect != PB_IMG_EFFECT_NORMAL) {
		UINT32 diskFreeSpace;
#ifdef DOS32_SUPPORT//jintao.liu 2008-5-21 add for mantis 24632
		diskFreeSpace = (UINT32)1024 * (UINT32)DOS_GetDiskSpace();
#else
		diskFreeSpace = (UINT32)G_DOS_ClusterSize * (UINT32)DOS_GetDiskSpace();
#endif
		//printf(">>free space = %lu<<\n",diskFreeSpace);
		if (diskFreeSpace < 1000000)
		{
			//printf(">>free space = %lu<<\n",diskFreeSpace);
			//sp1kDispImgWinEn(0);
			sp1kOsdSelWinSet(-1, -1, -1, -1, 0, -1);
			uiUpdateOSDMemFull();
			osMsgPost(SP1K_MSG_STATE_TO_STILL_PLAY);
			//return;
		}
		else {
			appUiBusyWait(250, 0);
			sp1kPbFileInfoGet(DOS_FileIndexGet(pbFile.dwIndex), &fileInfo);
			if(imgEffect<PB_IMG_EFFECT_MAX) {
				sp1kPbEffectSet(&fileInfo, imgEffect);
			}
/* ------ Note: Demo code zone start flag, don't modify or delete this line!!! ------ */
			else {
				sp1kPbDistortView(fileInfo.FileIdx, imgEffect-PB_IMG_EFFECT_MAX);
				sp1kPbDistortSave(fileInfo.FileIdx, imgEffect-PB_IMG_EFFECT_MAX);
			}	
/* ------ Note: Demo code zone end flag, don't modify or delete this line!!! ------ */		
			appUiBusyExit();
			
			pbFile.dwIndex = sp1kPbFileCntGet();			
			sp1kPbSingleImgPlay(DOS_FileIndexGet(pbFile.dwIndex));
			osMsgPost(SP1K_MSG_STATE_TO_STILL_PLAY);
		}
	}

	return SUCCESS;
}

//-----------------------------------------------------------------------------
//appMenuEvent_ImgResize
//-----------------------------------------------------------------------------

/**
 * @brief		appMenuEvent_ImgResize
 * @param	NULL
 * @retval	NULL
 * @see
 * @author	Phil Lin
 * @since		2008-11-11
 * @todo		Something need to be done.
 * @bug 	a bug need to be resolved.
*/

UINT8 appMenuEvent_ImgResize(UINT32 menuPos)
{
	PBFile_t fileInfo;
	UINT8 size;

	//add for mantis for #37054@strat
	if(1 == appSDProtectStatusGet()) //card lock remainder
	{
		uiOsdDialogDisp(ID_STR_CARD_LOCKED_, 1000);
		menuProcDisp();
		return FAIL;
	}
	//add for mantis for #37054@end

	appUiBusyWait(250, 0);
	sp1kPbFileInfoGet(DOS_FileIndexGet(pbFile.dwIndex), &fileInfo);

	switch (menuPos) {
		case MENU_MARK_RESIZE_3M:
			size = PRV_SIZE_3M;
			break;
		case MENU_MARK_RESIZE_1M:
			size = PRV_SIZE_1M;
			break;
		case MENU_MARK_RESIZE_VGA:
			size = PRV_SIZE_VGA;
			break;
		default:
			break;
	}
	
	//jintao.liu 2008-6-12 add for mantis 25700 
	//check if memory full?
	{
		UINT32 diskFreeSpace;
		UINT8 ret;
	
	#ifdef DOS32_SUPPORT
		diskFreeSpace = (UINT32)1024 * (UINT32)DOS_GetDiskSpace();
	#else
		diskFreeSpace = (UINT32)G_DOS_ClusterSize * (UINT32)DOS_GetDiskSpace();
	#endif

		if (diskFreeSpace < 1000000)
		{
			sp1kOsdSelWinSet(-1, -1, -1, -1, 0, -1);
			uiUpdateOSDMemFull();
			osMsgPost(SP1K_MSG_STATE_TO_STILL_PLAY);
		}
		else
		{
			ret = appPbImgResize(&fileInfo, size);
			appUiBusyExit();
		
			if(ret == SUCCESS)//xian ++ 20080703
				pbFile.dwIndex = sp1kPbFileCntGet();
			sp1kPbSingleImgPlay(DOS_FileIndexGet(pbFile.dwIndex));
			osMsgPost(SP1K_MSG_STATE_TO_STILL_PLAY);
		}
	}

	return SUCCESS;
}

/* ------ Note: Demo code zone start flag, don't modify or delete this line!!! ------ */
//-----------------------------------------------------------------------------
//appMenuEvent_PbFrameSave
//-----------------------------------------------------------------------------

/**
 * @brief		appMenuEvent_PbFrameSave
 * @param	NULL
 * @retval	NULL
 * @see
 * @author	Phil Lin
 * @since		2009-04-28
 * @todo		Something need to be done.
 * @bug 	a bug need to be resolved.
*/


UINT8 appMenuEvent_PbFrameSave(UINT8 item)
{
	UINT32 diskFreeSpace;
	
	if (item != PRV_PHOTO_FRAME_OFF) 
	{
			
		sp1kOsdClear(ID_ICON_NONE, 0);
		sp1kOsdSelWinSet(-1, -1, -1, -1, 0, -1);
		if(1 == appSDProtectStatusGet()) //card lock remainder
		{
			uiOsdDialogDisp(ID_STR_CARD_LOCKED_, 1000);
			appPbPhotoFrameSet(PRV_PHOTO_FRAME_OFF,0);
			menuExit();	
		}
		else
		{	
			#ifdef DOS32_SUPPORT
				diskFreeSpace = (UINT32)1024 * (UINT32)DOS_GetDiskSpace();
			#else
				diskFreeSpace = (UINT32)G_DOS_ClusterSize * (UINT32)DOS_GetDiskSpace();
			#endif
			
			if (diskFreeSpace < 1000000)
			{
				sp1kOsdSelWinSet(-1, -1, -1, -1, 0, -1);
				uiUpdateOSDMemFull();
				appPbPhotoFrameSet(PRV_PHOTO_FRAME_OFF,0);
				menuExit();
			}
			else
			{
				appPbPhotoFrameSet(item,1);
				menuExit();
			}
		 }
	} 
	else 
	{
		menuProcDisp();
	}

	return SUCCESS;

}


/* ------ Note: Demo code zone end flag, don't modify or delete this line!!! ------ */



